package com.ge.modules.api.controller;

import com.ge.common.annotation.AuthIgnoreApi;
import com.ge.common.annotation.LoginUserApi;
import com.ge.common.utils.PageUtils;
import com.ge.common.utils.Query;
import com.ge.common.utils.R;
import com.ge.modules.api.service.TbCommodityTypeService;
import com.ge.modules.entity.TbCommodityTypeEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;


/**
 * 商品类型表
 *
 * @author lanyonglin
 * @email www.baidu.com
 * @date 2018-04-20 15:51:26
 */
@RestController
@RequestMapping("/api/user/tbCommodityType")
public class TbCommodityTypeController {
    @Autowired
    private TbCommodityTypeService tbCommodityTypeService;

    /**
     * 查询类型列表 根据类型
     *
     * @param params
     * @return
     */
    @AuthIgnoreApi
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params) {
        //查询列表数据
        Query query = new Query(params);
        List<TbCommodityTypeEntity> commodityTypeList = tbCommodityTypeService.queryList(query);
        int total = tbCommodityTypeService.queryTotal(query);
        PageUtils pageUtil = new PageUtils(commodityTypeList, total, query.getLimit(), query.getPage());
        return R.ok().put("page", pageUtil);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Integer id) {
        TbCommodityTypeEntity commodityType = tbCommodityTypeService.queryObject(id);
        return R.ok().put("commodityType", commodityType);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody TbCommodityTypeEntity commodityType) {
        tbCommodityTypeService.save(commodityType);

        return R.ok();
    }


}
